How to Use Variables

Contents|Index|Previous|Next
How to use variables

A variable is a name defined in a makefile to represent a string of text, called the variables value. These values are substituted by explicit request into targets, dependencies, commands, and other parts of the makefile. In some other versions of make, variables are called macros.

See the following documentation for more discussion.

- Basics of variable references
- The two flavors of variables
- Advanced features for reference to variables

- Substitution references
- Computed variable Names

- How variables get their values
- Setting variables
- Appending more text to variables
- The override directive
- Defining variables verbatim
- Variables from the environment

Variables and functions in all parts of a makefile are expanded when read, except for the shell commands in rules, the right-hand sides of variable definitions using =, and the bodies of variable definitions using the define directive.

Variables can represent lists of file names, options to pass to compilers, programs to run, directories to look in for source files, directories to write output in, or anything else you can imagine.

A variable name may be any sequence of characters not containing :, #, =, or leading or trailing whitespace. However, variable names containing characters other than letters, numbers, and underscores should be avoided because they may be given special meanings in the future, and with some shells they cannot be passed through the environment to a sub-make (see Communicating variables to a sub-make ).

Variable names are case-sensitive. The names foo, FOO, and Foo all refer to different variables.

It is traditional to use uppercase letters in variable names, but we recommend using lowercase letters for variable names that serve internal purposes in the makefile, and reserving uppercase for parameters that control implicit rules or for parameters that the user should override with command options (see Overriding variables).

A few variables have names that are a single punctuation character or just a few characters. These are the automatic variables, and they have particular specialized uses. See Automatic variables.

Top|Contents|Index|Previous|Next